package com.xszx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xszx.entity.TDept;
import com.xszx.entity.TUser;
import com.xszx.service.TUserService;
import com.xszx.mapper.TUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 34129
* @description 针对表【t_user】的数据库操作Service实现
* @createDate 2024-01-08 20:40:47
*/
@Service
public class TUserServiceImpl extends ServiceImpl<TUserMapper, TUser>
    implements TUserService{

    @Autowired
    private TUserMapper userMapper;

    @Override
    public TUser isOnly(String phone, String idcard) {
        return userMapper.isOnly(phone,idcard);
    }

    @Override
    public TUser isAccount(String account) {
        return userMapper.isAccount(account);
    }

    @Override
    public void addUser(TUser tUser2) {
        userMapper.addUser(tUser2);
    }
    /**
     * 查询所有用户
     * @return
     */
    @Override
    public List<TUser> selectUser() {

        return userMapper.selectUser();
    }

    /**
     * 根据账号查询数据
     * @param account
     * @return
     */
    @Override
    public TUser getUserByAccount(String account) {
        return userMapper.getUserByAccount(account);
    }

    /**
     * 判断登录时用户名和密码是否正确
     * 2：没有该账号的数据
     * 3：密码不对
     * 1：登录成功
     * @param user
     * @return
     */
    @Override
    public int ifUnameAndPwd(TUser user) {

        //根据账号查询对应的数据
        TUser userByAccount = getUserByAccount(user.getAccount());
        System.out.println(userByAccount);
        if(userByAccount==null || !userByAccount.getAccount().equals(user.getAccount())){
            return 2;
        } else if (!userByAccount.getPassword().equals(user.getPassword())){
            return 3;
        }

        return 1;
    }

    @Override
    public void perfectUser(TUser tUser) {
        userMapper.updateUser(tUser);
    }

    @Override
    public void deleteUserById(int i) {
        userMapper.deleteUserById(i);
    }

    @Override
    public TDept getUserDeptByDid(long did) {
        return userMapper.getUserDeptByDid(did);
    }

    @Override
    public void updateUser(TUser user) {
        userMapper.updateUser(user);
    }

    @Override
    public List<TUser> selectUser(TUser tUser) {
        return userMapper.selectUserByCheck(tUser);
    }


}




